package com.lb.thread;

/**
 * @ClassName RunnableDemo1
 * @Author LB
 * @Date 2021/12/22 9:21
 **/
public class RunnableDemo implements Runnable{

    private int ticket = 100;

    @Override
    public void run() {
        while (true){
            synchronized (this){
                if(ticket>0){
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"卖了一张票,还剩:"+--ticket);
                }
            }
        }
    }
}